<?php

class Renderer {


  public static function getValueKey($name, $array, $defaultKey="", $defaultValue="") {
    $retVal = "";
    if (key_exists($name, $array)) {
      $retVal = $array[$name];
    } else {
      if ($defaultKey!="") {
        if(key_exists($defaultKey, $array)) {
          $retVal = $array[$defaultKey];
        } else {
          $retVal = $defaultValue;
        }
      } else {
        $retVal = $defaultValue;
      }
    }
    return $retVal;
  }

  public static function renderAuthor($itemFrom) {
    $authorId = $itemFrom["id"];
    echo "<img src=\"http://graph.facebook.com/$authorId/picture\" valign=\"middle\">";
    echo $itemFrom["name"];
    echo "<br />";
  }

  public static function renderVideo($item) {
    echo "<pre>";
    print_r( $item );
    echo "</pre>";
  }
  
  public static function renderStatus($item) {
    echo "<pre>";
    print_r( $item );
    echo "</pre>";
  }

  
  public static function renderPhotos($item) {
    echo "<pre>";
    print_r( $item );
    echo "</pre>";
  }
  public static function renderLink($item) {

    // Recupero il NOME del link
    $name = self::getValueKey("name", $item, "link", "Link Condiviso" );
    echo "<div id=\"link_".$item["id"]."\" class=\"item_link\">";
    // recupero le informazioni relative all'autore
    self::renderAuthor($item["from"]);
    $message = self::getValueKey("message", $item, "", "" );
    echo " <b>Messaggio</b>: <i>".$message."</i><br />";

    $picture = self::getValueKey("picture", $item, "", "" );
    if ($picture != "") {
      echo "<img src=\"$picture\"><br />";
    }
    echo  "<b>Link</b>: <a href=\"".$item["link"]."\">$name</a><br />";
    // recupero la picture del link


    // recupero altre informazioni relativamente al link quali icon, caption, description
    echo "<b>Icona Link</b>: <img src=\"".$item["icon"]."\"><br />";
    $caption = self::getValueKey("caption", $item, "", "" );
    echo "<b>Didascalia</b>: ".$caption."<br />";
    $description = self::getValueKey("description", $item, "", "" );
    echo "<b>Descrizione</b>: ".$description."<br />";
    $updateTime = self::getValueKey("updated_time", $item, "", "" );
    echo "<b>Ultimo Aggiornamento</b>: ".$updateTime."<br />";
    echo "<pre>";
    print_r( $item );
    echo "</pre>";
    echo "<div>";
  }
}
